#!perl
################################################################################
# WeBWorK Online Homework Delivery System
# Copyright &copy; 2000-2018 The WeBWorK Project, http://openwebwork.sf.net/
# $CVSHeader: webwork2/conf/database.conf.dist,v 1.38 2007/08/13 22:59:51 sh002i Exp $
# 
# This program is free software; you can redistribute it and/or modify it under
# the terms of either: (a) the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version, or (b) the "Artistic License" which comes with this package.
# 
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
# Artistic License for more details.
################################################################################

=head1 NAME

database.conf - define standard database layouts

=head1 SYNOPSIS

In defaults.config:

 include "conf/database.conf";
 *dbLayout = $dbLayouts{layoutName};

=head1 DESCRIPTION

This file contains definitions for the commonly-used database layouts. Database
layouts consist of all the information necessary to describe how to access data
used by WeBWorK. For more information on the format of a database layout,
consult the documentation for the WeBWorK::DB module.

A database layout is selected from the list of possible layouts by adding a
line like the one below to the F<localOverrides.conf> or F<course.conf> file.

 $dbLayoutName = "layoutName";
 *dbLayout = $dbLayouts{$dbLayoutName};

=cut

%dbLayouts = (); # layouts are added to this hash below

=head2 THE SQL_SINGLE DATABASE LAYOUT

The C<sql_single> layout is similar to the C<sql> layout, excpet that it uses a
single database for all courses. This is accomplised by prefixing each table
name with the name of the course. The names and passwords of these accounts are
given as parameters to each table in the layout.

 username     the username to use when connecting to the database
 password     the password to use when connecting to the database

Be default, username is "webworkRead" and password is "". It is not recommended
that you use only a non-empty password to secure database access. Most RDBMSs
allow IP-based authorization as well. As the system administrator, IT IS YOUR
RESPONSIBILITY TO SECURE DATABASE ACCESS.

Don't confuse the account information above with the accounts of the users of a
course. This is a system-wide account which allow WeBWorK to talk to the
database server.

Other parameters that can be given are as follows:

 tableOverride  an alternate name to use when referrring to the table (used
                when a table name is a resereved word)
 fieldOverride  a hash mapping WeBWorK field names to alternate names to use
                when referring to those fields (used when one or more field
				names are reserved words)
 debug          if true, SQL statments are printed before being executed

=cut


# params common to all tables

my %sqlParams = (
	username => $database_username,
	password => $database_password,
	debug    => $database_debug,
    ($ENABLE_UTF8MB)?(mysql_enable_utf8mb4 =>1):(mysql_enable_utf8 => 1),
	# kinda hacky, but needed for table dumping
	mysql_path     => $externalPrograms{mysql},
	mysqldump_path => $externalPrograms{mysqldump},
);

$dbLayouts{sql_single} = {
        locations => {
                record => "WeBWorK::DB::Record::Locations",
                schema => "WeBWorK::DB::Schema::NewSQL::Std",
                driver => "WeBWorK::DB::Driver::SQL",
                source => $database_dsn,
                engine => $database_storage_engine,
                character_set => $database_character_set,
                params => { %sqlParams,
                        non_native => 1,
                },
        },
        location_addresses => {
                record => "WeBWorK::DB::Record::LocationAddresses",
                schema => "WeBWorK::DB::Schema::NewSQL::Std",
                driver => "WeBWorK::DB::Driver::SQL",
                source => $database_dsn,
                engine => $database_storage_engine,
                character_set => $database_character_set,
                params => { %sqlParams,
                        non_native => 1,
                },
        },
        depths => {
				record => "WeBWorK::DB::Record::Depths",
				schema => "WeBWorK::DB::Schema::NewSQL::Std",
				driver => "WeBWorK::DB::Driver::SQL",
				source => $database_dsn,
        		engine => $database_storage_engine,
				params => { %sqlParams,
					non_native => 1,
		},
	},
	password => {
		record => "WeBWorK::DB::Record::Password",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
        character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_password",
		},
	},
	permission => {
		record => "WeBWorK::DB::Record::PermissionLevel",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_permission",
		},
	},
	key => {
		record => "WeBWorK::DB::Record::Key",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_key",
			fieldOverride => { key => "key_not_a_keyword" },
		},
	},
	user => {
		record => "WeBWorK::DB::Record::User",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_user",
		},
	},
	set => {
		record => "WeBWorK::DB::Record::Set",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_set",
			#fieldOverride => { visible => "published" }, # for compatibility -- visible was originally called published
		},
	},
	set_user => {
		record => "WeBWorK::DB::Record::UserSet",
		schema => "WeBWorK::DB::Schema::NewSQL::NonVersioned",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_set_user",
			#fieldOverride => { visible => "published" }, # for compatibility -- visible was originally called published
		},
	},
	set_merged => {
		record => "WeBWorK::DB::Record::UserSet",
		schema => "WeBWorK::DB::Schema::NewSQL::Merge",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		depend => [qw/set_user set/],
		params => { %sqlParams,
			non_native => 1,
			merge      => [qw/set_user set/],
		},
	},
	set_version => {
		record => "WeBWorK::DB::Record::SetVersion",
		schema => "WeBWorK::DB::Schema::NewSQL::Versioned",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
        engine => $database_storage_engine,
		params => { %sqlParams,
			non_native => 1,
			tableOverride => "${courseName}_set_user",
			#fieldOverride => { visible => "published" }, # for compatibility -- visible was originally called published

		},
	},
	set_version_merged => {
		record => "WeBWorK::DB::Record::SetVersion",
		schema => "WeBWorK::DB::Schema::NewSQL::Merge",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		depend => [qw/set_version set_user set/],
		params => { %sqlParams,
			non_native => 1,
			merge      => [qw/set_version set_user set/],
		},
	},
        set_locations => {
                record => "WeBWorK::DB::Record::SetLocations",
                schema => "WeBWorK::DB::Schema::NewSQL::Std",
                driver => "WeBWorK::DB::Driver::SQL",
                source => $database_dsn,
                engine => $database_storage_engine,
                character_set => $database_character_set,
                params => { %sqlParams,
                        tableOverride => "${courseName}_set_locations"
                },
        },
        set_locations_user => {
                record => "WeBWorK::DB::Record::UserSetLocations",
                schema => "WeBWorK::DB::Schema::NewSQL::Std",
                driver => "WeBWorK::DB::Driver::SQL",
                source => $database_dsn,
                engine => $database_storage_engine,
                character_set => $database_character_set,
                params => { %sqlParams,
                        tableOverride => "${courseName}_set_locations_user"
                },
        },
	problem => {
		record => "WeBWorK::DB::Record::Problem",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_problem"
		},
	},
	problem_user => {
		record => "WeBWorK::DB::Record::UserProblem",
		schema => "WeBWorK::DB::Schema::NewSQL::NonVersioned",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_problem_user"
		},
	},
	problem_merged => {
		record => "WeBWorK::DB::Record::UserProblem",
		schema => "WeBWorK::DB::Schema::NewSQL::Merge",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		depend => [qw/problem_user problem/],
		params => { %sqlParams,
			non_native => 1,
			merge      => [qw/problem_user problem/],
		},
	},
	problem_version => {
		record => "WeBWorK::DB::Record::ProblemVersion",
		schema => "WeBWorK::DB::Schema::NewSQL::Versioned",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			non_native => 1,
			tableOverride => "${courseName}_problem_user",
		},
	},
	problem_version_merged => {
		record => "WeBWorK::DB::Record::ProblemVersion",
		schema => "WeBWorK::DB::Schema::NewSQL::Merge",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		depend => [qw/problem_version problem_user problem/],
		params => { %sqlParams,
			non_native => 1,
			merge      => [qw/problem_version problem_user problem/],
		},
	},
	setting => {
		record => "WeBWorK::DB::Record::Setting",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_setting"
		},
	},
   	achievement => {
		record => "WeBWorK::DB::Record::Achievement",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_achievement"
		},
	},
	past_answer => {
		record => "WeBWorK::DB::Record::PastAnswer",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			    tableOverride => "${courseName}_past_answer"
	 	},
    },

	achievement_user => {
		record => "WeBWorK::DB::Record::UserAchievement",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_achievement_user"
	 	},
    },
	global_user_achievement => {
		record => "WeBWorK::DB::Record::GlobalUserAchievement",
		schema => "WeBWorK::DB::Schema::NewSQL::Std",
		driver => "WeBWorK::DB::Driver::SQL",
		source => $database_dsn,
    	engine => $database_storage_engine,
    	character_set => $database_character_set,
		params => { %sqlParams,
			tableOverride => "${courseName}_global_user_achievement"
		},
	},

};

# include ("conf/database.conf");  # uncomment to provide local overrides


=head1 DATABASE LAYOUT METADATA

=over

=item @dbLayout_order

Database layouts listed in this array will be displayed first, in the order
specified, wherever database layouts are listed. (For example, in the "Add
Course" tool.) Other layouts are listed after these.

=cut

@dbLayout_order = qw/sql_single sql_moodle/;

=item %dbLayout_descr

Hash mapping database layout names to textual descriptions.

=cut

%dbLayout_descr = (
	sql_single => "Uses a single SQL database to record WeBWorK data for all courses using this layout. This is the recommended layout for new courses.",
#	sql_moodle => "Simiar to sql_single, but uses a Moodle database for user, password, and permission information. This layout should be used for courses used with wwmoodle.",
);

=back

=cut
